<!-- box menu -->
<?php $this->renderPartial("application.views.layouts._menu");?>
<!-- End box menu -->
<?php 
       $items = isset($_SESSION["items"]) ? $_SESSION["items"]:array();    
       $countData = count($data);
       $number_row =  $countData/3 + ($countData%3>0?1:0);
       $title_embed =  isset($_SESSION["title_embed"])?$_SESSION["title_embed"]:'';
       $type_cat = isset($type_cat)?$type_cat:"1";
       $type_data = isset($type_data)?$type_data:"1";
       
      // var_dump($data_embed);die;
?>
 <script type="text/javascript">
    function addItem(catId, dataId){
        var strUrl = "<?php echo Url::createUrl("tool/ajaxAddItem") ?>";
     
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                catId:catId,
                dataId:dataId 
            },
            success: function(msg){  
          
                if(msg==1){    
                    var html = $("#item_"+catId+"_"+dataId).html();
                    var html = '<div class="Moi4_1" id="item_selected_'+catId+'_'+dataId+'" onclick="removeItem('+catId+','+dataId+')">'+html+'</div>';
                    $("#item_products").append(html);
                  
                  }
            }          
        });
    }
    
    
     function removeItem(catId,dataId){
        var strUrl = "<?php echo Url::createUrl("tool/ajaxRemoveItem") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                catId:catId,
                dataId:dataId 
            },
            success: function(msg){
                if(msg==1){
                    $('#item_selected_'+catId+'_'+dataId+'').remove();
                }
            }          
        });
    }
    
 </script>
<div class="about">
        <?php $this->widget("BoxLogin");?>
        <h1><a><img src="<?php  echo Yii::app()->params['static_url']; ?>images/tenweb-icon-banner.png" alt="" class="kc_TB_td" /></a>
            <a href="#" class="xanhdam">Tạo mã nhúng</a>
        </h1>
        <div class="Tma">
            <div class="Tma_1">
                <a href="#" class="button_Tma">1</a><a href="#" class="denxam">Chọn sản phẩm</a>
                &nbsp;&nbsp;&nbsp;
                <a href="#" class="button_Tma_2">2</a><a href="#" class="denxam">Chọn kiểu hiện thị</a>
                &nbsp;&nbsp;&nbsp;
                <a href="#" class="button_Tma_2">3</a><a href="#" class="denxam">Chọn giao diện</a>
                &nbsp;&nbsp;&nbsp;
                <a href="#" class="button_Tma_2">4</a><a href="#" class="denxam">Lấy mã nhúng</a>
            </div>
            
        </div>
        <div>
            <h2>
            <img src="<?php  echo Yii::app()->params['static_url']; ?>images/tenweb-icon-taomanhung-giaodien.png" alt="" width="14" height="16" class="kc_TB_td" />Chọn Giao Diện
            </h2>  
        </div>
   
   <form name="embedStep1Form" action="<?php echo  Url::createUrl('tool/embedStep1')?>" method="post"> 
        <div class="Moi1">
                <?php
            if(!empty($error))
             echo $error;
            ?>
        </div>
        
         <div class="Moi1">
                <strong>Nhập tên mã nhúng</strong><br />
               <input name="title_embed" cols="0" rows="2" class="onhap_banner" value="<?php  echo $title_embed;?>"/>
        </div>
       
        <div class="Moi2">
            <a class="do" href="<?php echo  Url::createUrl('tool/embedStep1',array("type_cat"=>1))?>"><strong>Game Online</strong></a>&nbsp;&nbsp;&nbsp;
            <a class="do" href="<?php echo  Url::createUrl('tool/embedStep1',array("type_cat"=>2))?>"><strong>Game Offline</strong></a>&nbsp;&nbsp;&nbsp;
            <a class="do" href="<?php echo  Url::createUrl('tool/embedStep1',array("type_cat"=>4))?>"><strong>Ứng Dụng</strong></a>&nbsp;&nbsp;&nbsp;
        </div>
        
        <div class="Moi3">
            <div class="Tma_1">
              <a href="<?php echo  Url::createUrl('tool/embedStep1',array("type_cat"=>$type_cat,"type_data"=>1))?>" class="button_Tma xanhdam">Mới </a>
                &nbsp;
              <a href="<?php echo  Url::createUrl('tool/embedStep1',array("type_cat"=>$type_cat,"type_data"=>2))?>" class="button_Tma_3 xanhdam">Hot</a>
                &nbsp;
              <a href="<?php echo  Url::createUrl('tool/embedStep1',array("type_cat"=>$type_cat,"type_data"=>3))?>" class="button_Tma_3 xanhdam">Hút Sms</a>
                &nbsp;
              <a href="<?php echo  Url::createUrl('tool/embedStep1',array("type_cat"=>$type_cat,"type_data"=>4))?>" class="button_Tma_3 xanhdam">Hút Card</a>
            </div>
            <p style="padding-left: 10px;">Click vào từng sản phẩm để chọn</p>
            <?php
            $i=0;
            while($i<$number_row)  {
                echo  "<div class=\"Moi4\">" ;
                $j =   $i * 3 ;
                $number_item_on_row=   (($i+1)*3)>$countData?$countData:(($i+1)*3);
                while($j<$number_item_on_row)
                {   
                    if($type_cat == 4){
                      
                        $data[$j]["categoryId"]= 0;   
                    } 
                    
                     if($type_cat <3){
                        $link_img=Common::getImageDomain($data[$j]['picture'],"game",$data[$j]['create_date'],"",2);
                    }else{
                        $link_img = Common::getImageDomain($data[$j]["picture"], "app",$data[$j]['create_date'], "",3);   
                        
                    }
                    $img_error=Yii::app()->params['static_url'].'/images/farmvui52.png';                                       
            ?>
                 <div class="Moi4_1" id="item_<?php echo $data[$j]["categoryId"]; ?>_<?php echo $data[$j]["id"]; ?>"  style="cursor: pointer;" onclick="addItem('<?php echo $data[$j]["categoryId"]; ?>','<?php echo $data[$j]["id"]; ?>')">
                      <img src="<?php echo $link_img;?>" alt="" width="90" height="87" class="kc_DV" /><br /><strong>
                        <?php echo $data[$j]["title"]?>
                       </strong>
                </div>
             <?php       
                $j++;                
                }
                $i++; 
                echo "<div class=\"both\"></div>";
                echo "</div>";
            }
        ?>
          
            <div class="Moi_5">
                         <?php echo $paging;?>
            </div>
        </div>
        
        <div class="Moi_6" >
            <div class="Moi6_1" >
                <div  id="item_products">
                          <?php 
                                    foreach($items as $key=>$value){
                                        if($value["categoryId"] >0){
                                            $link_img=Common::getImageDomain($value['picture'],"game",$value['create_date'],'',2);
                                        }else{
                                            $link_img = Common::getImageDomain($value["picture"], "app", $value['create_date'], "",3);
                                        }
                                        $img_error=Common::getImgError(); 
                                    ?>
                                    <div class="Moi4_1" id="item_selected_<?php echo $value["categoryId"].'_'.$value["id"] ?>" onclick="removeItem('<?php echo $value["categoryId"]?>','<?php echo $value["id"];?>')">
                                    <img src="<?php echo $link_img;?>" alt="" width="90" height="87" class="kc_DV" />
                                    <br/><strong><?php echo $value["title"]?></strong>
                                     </div>
                                    <?php }?>             
                 </div>
                <div class="Moi4_1">
                       &nbsp;
                </div>
                <div class="both"></div>
            </div>
        </div>
        
        <div class="Tma_8">
                    <input type="submit" name="submit_b1" value="Tiếp Theo" class="button_DNHT_1"/>             
                    <a href="<?php echo Url::createUrl("tool/embedStep1?submit=delete") ?>" class="button_DNHT_2">Hủy</a>
         </div>
         
        <div class="Tma_9">
              <img src="<?php echo Yii::app()->params['static_url'];?>images/tenweb-icon-DS-ma-nhung.png" alt="" width="11" height="13" class="kc_TB_td" />Danh Sách Mã Nhúng Dựng Sẵn
         </div>
         
         <div class="Tma_10">
             <ul>
               <?php
               foreach($data_embed as $row){
                  
               ?>
                 <li>
                <a href="<?php echo Url::createUrl("tool/embedDetailByAdmin",array("embed_id"=>$row["id"])) ?>"><img src="<?php echo Yii::app()->params['static_url'];?>images/tenweb-icon-cacloaimanhung.png" alt="" width="24" height="16" class="kc_TB_td" /><?=$row["title"]?></a>
                </li>
               <?php
               }
?>
            </ul>
         </div>
         
          <div class="Tma_9">
             <a href="<?php echo Url::createUrl("tool/embedByUser") ?>" class="do"> <img src="<?php echo Yii::app()->params['static_url'];?>images/tenweb-icon-DS-ma-nhung.png" alt="" width="11" height="13" class="kc_TB_td" />Danh Sách Mã Nhúng Bạn Tạo
             </a>
         </div>
         
         </form>
</div>
